package com.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.beans.Position;
import com.beans.User;
import com.dao.PositionDao;
import com.vo.Page;

public class PositionDaoImpl extends UniversalDaoImpl implements PositionDao {

	public Page queryList(int pageNo, int pageSize, Position p) {
		String sql = "select p.id,companyID,c.cname company,dbo.getCodeName('zw',name) name,dbo.getCodeName('1',region) region,dbo.getCodeName('2',sex) sex,wages,dbo.getCodeName('5',workType) workType,persons,days,createtime,detail,orderid,p.views,p.fix from j_position p left join j_company c on p.companyID=c.id where 1=1";
		Map param = new HashMap();
		if (p.getCompany() != null && p.getCompany().getId() > 0)
			param.put("companyId=?", p.getCompany().getId());
		if (p.getDetail() != null && !"".equals(p.getDetail()))
			param.put("detail like ?", "%" + p.getDetail() + "%");
		if (p.getName() != null && !"".equals(p.getName()))
			param.put("name like ?", p.getName() + "%");
		if (p.getId() > 0)
			param.put("p.id=?", p.getId());
		if (p.getRegion() != null && !"".equals(p.getRegion()))
			param.put("region like ?", p.getRegion() + "%");
		return Page(pageNo, pageSize, sql, "id", param);
	}

	public void fix(int positionID, int fix) {
		String sql = "update j_position set fix=" + fix + " where id="
				+ positionID;
		logger.info(sql);
		excuteSQL(sql);
	}

	public List topFixPosition(int top) {
		String sql = "select top "+top+" p.id,companyID,c.cname company,dbo.getCodeName('zw',name) name,dbo.getCodeName('1',region) region,dbo.getCodeName('2',sex) sex,wages,dbo.getCodeName('5',workType) workType,persons,days,createtime,detail,orderid,p.views,p.fix from j_position p left join j_company c on p.companyID=c.id order by p.fix desc";
		logger.info(sql);
		return getJdbcTemplate().queryForList(sql);
	}

	public List topNewPosition(int top) {
		String sql = "select top "+top+" p.id,companyID,c.cname company,dbo.getCodeName('zw',name) name,dbo.getCodeName('1',region) region,dbo.getCodeName('2',sex) sex,wages,dbo.getCodeName('5',workType) workType,persons,days,createtime,detail,orderid,p.views,p.fix from j_position p left join j_company c on p.companyID=c.id order by p.createtime desc";
		logger.info(sql);
		return getJdbcTemplate().queryForList(sql);
	}

	public List topViewPosition(int top) {
		String sql = "select top "+top+" p.id,companyID,c.cname company,dbo.getCodeName('zw',name) name,dbo.getCodeName('1',region) region,dbo.getCodeName('2',sex) sex,wages,dbo.getCodeName('5',workType) workType,persons,days,createtime,detail,orderid,p.views,p.fix from j_position p left join j_company c on p.companyID=c.id order by p.views desc";
		logger.info(sql);
		return getJdbcTemplate().queryForList(sql);
	}

	public void delete(int id) {
		String sql = "delete j_position where id="+id;
		logger.info(sql);
		excuteSQL(sql);
	}
}